package utils
{
	import events.ImageUtilEvent;
	
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.utils.ByteArray;

	public class ImageUtil extends EventDispatcher
	{
		[Event(name="imageLoadComplete", type="events.ImageUtilEvent")]

		public var data:Object = new Object;

		public function ImageUtil(target:IEventDispatcher=null)
		{
			super(target);
		}
		
		public function BitmapFromBitmapData(pByteArray:ByteArray):void{
			var l:Loader = new Loader();
			l.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
			l.loadBytes(pByteArray);
		}
		
		private function onLoadComplete(e:Event):void{
			var ev:ImageUtilEvent = new ImageUtilEvent(ImageUtilEvent.IMAGE_LOAD_COMPLETE);
			ev.bitmap = e.currentTarget.content as Bitmap;
			dispatchEvent(ev);
		}
		
	}
}